home *** CD-ROM | disk | FTP | other *** search
- /*
- File: CAArbitr.cpp
-
- Contains: Container Application Library source - Arbitration
-
- Written by: Steve Foley, Greg Ames, David Nelson
-
- Copyright: © 1994 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- <15> 11/21/95 RB Made all acquire operation use temp objects
- <14> 5/19/95 SJF Fix RequestModalFocus
- <8> 5/15/95 RB Adding CA_CATCH
- <7> 5/12/95 RB Implementing CARequestStandardFocus() and
- CARelinquishStandardFocus()
- <6> 4/23/95 RB Implementing CAInstallFocusNotification
- <5> 4/23/95 RB Added GetFocusOwner() routine.
- <4> 4/23/95 RB Implemented Modal focus routines
- <3+> 2/28/95 SJF Add debug stuff to API functions.
- <3> 2/13/95 SJF Interim checkin to update project database
- <3) 12/15/94 SJF change somGetGlobalEnvironment to _gpProxyShell->GetGlobalEnvironment
- <2> 10/30/94 GCA,DHN All mods to make project compile with no
- errors under OpenDoc b1 (with SOM).
- <1> 10/16/94 SJF first written
-
- To Do:
- implement
- */
-
-
- #ifndef _CASESSN_
- #include "CASessn.h"
- #endif
-
- #ifndef _CADEBUG_
- #include "CADebug.h"
- #endif
-
- #ifndef _CAERROR_
- #include "CAError.h"
- #endif
-
- #ifndef _CADOCPRIV_
- #include "CADocPriv.h"
- #endif
-
- #ifndef _CAFRMUTL_
- #include "CAFrmUtl.h"
- #endif
-
- #ifndef _ODUTILS_
- #include <ODUtils.h>
- #endif
-
- #ifndef SOM_ODWindowState_xh
- #include <WinStat.xh>
- #endif
-
- #ifndef SOM_ODPart_xh
- #include <Part.xh>
- #endif
-
- #ifndef SOM_ODFoci_xh
- #include <Foci.xh>
- #endif
-
- #ifndef SOM_ODFocusSet_xh
- #include <FocusSet.xh>
- #endif
-
- #ifndef SOM_ODWindow_xh
- #include <Window.xh>
- #endif
-
- #ifndef _CAPROXYPARTDEF_
- #include "CAProxyPartDef.h"
- #endif
-
- #ifndef CAProxyExtension_API
- #include "CAProxyExtension.xh"
- #endif
-
- #ifndef _TEMPOBJ_
- #include <TempObj.h>
- #endif
-
- #pragma segment CALib
-
-
- //-------------------------------------------------------------------------
- // Arbitration ***
- //-------------------------------------------------------------------------
-
- pascal Boolean CARequestStandardFocusSet( WindowPtr window )
- {
-
- Environment* ev = gCASession->GetEV();
- ODWindowState* windowState = gCASession->GetODSession()->GetWindowState(ev);
- Boolean result = false;
- ODFrame* rootFrame;
- ODFocusSet* focusSet;
-
- CA_TRY
-
- if (!window) THROW (kCAErrInvalidParameter);
-
- // Get the OD window
- TempODWindow tempWindow = windowState->AcquireODWindow(ev, window);
- THROW_IF_NULL (tempWindow);
-
- focusSet = gCASession->GetArbitrator()->CreateFocusSet(ev);
- THROW_IF_NULL (focusSet);
-
- focusSet->Add(ev, gCASession->GetODSession()->Tokenize(ev, kODKeyFocus));
- focusSet->Add(ev, gCASession->GetODSession()->Tokenize(ev, kODMenuFocus));
- focusSet->Add(ev, gCASession->GetODSession()->Tokenize(ev, kODSelectionFocus));
-
- // Need some error checking
-
- rootFrame = tempWindow->GetRootFrame(ev);
-
- TempODPart tempPart = rootFrame->AcquirePart(ev);
- THROW_IF_NULL (tempPart);
-
- result = gCASession->GetArbitrator()->RequestFocusSet(ev, focusSet, rootFrame);
-
- if (result)
- {
- tempPart->FocusAcquired(ev, gCASession->GetODSession()->Tokenize(ev, kODKeyFocus), rootFrame);
- tempPart->FocusAcquired(ev, gCASession->GetODSession()->Tokenize(ev, kODMenuFocus), rootFrame);
- tempPart->FocusAcquired(ev, gCASession->GetODSession()->Tokenize(ev, kODSelectionFocus), rootFrame);
- }
-
-
- CA_CATCH_ALL
- CA_ENDTRY
-
- ODDeleteObject (focusSet);
-
- return result;
- }
-
-
- //-------------------------------------------------------------------------
- pascal Boolean CARequestModalFocus( WindowPtr window )
- {
-
- // If the window is nil (no front doc window) return TRUE
-
- Environment* ev = gCASession->GetEV();
- ODWindowState* windowState = gCASession->GetODSession()->GetWindowState(ev);
- ODArbitrator* arbitrator = gCASession->GetArbitrator();;
- Boolean result = true;
- ODFrame* rootFrame;
-
- if (!window) return (true);
- if (!windowState->IsODWindow(ev, window)) return (true);;
-
- CA_TRY
-
- TempODWindow tempWindow = windowState->AcquireODWindow(ev, window);
- THROW_IF_NULL (tempWindow);
-
- rootFrame = tempWindow->GetRootFrame(ev);
-
- result = arbitrator->RequestFocus(ev,
- gCASession->GetODSession()->Tokenize(ev, kODModalFocus), rootFrame);
-
- CA_CATCH_ALL
- CA_ENDTRY
-
- return result;
- }
-
-
- //-------------------------------------------------------------------------
- pascal void CARelinquishStandardFocusSet( WindowPtr window )
- {
-
- Environment* ev = gCASession->GetEV();
- ODWindowState* windowState = gCASession->GetODSession()->GetWindowState(ev);
- Boolean result = false;
- ODFrame* rootFrame;
- ODFocusSet* focusSet;
-
- CA_TRY
-
- if (!window) THROW (kCAErrInvalidParameter);
-
- TempODWindow tempWindow = windowState->AcquireODWindow(ev, window);
- THROW_IF_NULL (tempWindow);
-
- focusSet = gCASession->GetArbitrator()->CreateFocusSet(ev);
- focusSet->Add(ev, gCASession->GetODSession()->Tokenize(ev, kODKeyFocus));
- focusSet->Add(ev, gCASession->GetODSession()->Tokenize(ev, kODMenuFocus));
- focusSet->Add(ev, gCASession->GetODSession()->Tokenize(ev, kODSelectionFocus));
-
- // Need some error checking
-
- rootFrame = tempWindow->GetRootFrame(ev);
-
- gCASession->GetArbitrator()->RelinquishFocusSet(ev, focusSet, rootFrame);
-
- CA_CATCH_ALL
- CA_ENDTRY
-
- ODDeleteObject (focusSet);
-
-
- }
-
-
- //-------------------------------------------------------------------------
- pascal void CARelinquishModalFocus( WindowPtr window )
- {
- Environment* ev = gCASession->GetEV();
- ODWindowState* windowState = gCASession->GetODSession()->GetWindowState(ev);
- ODArbitrator* arbitrator = gCASession->GetArbitrator();;
- Boolean result = false;
- ODFrame* rootFrame;
-
- if (!window) return;
- if (!windowState->IsODWindow(ev, window)) return;
-
- CA_TRY
-
- TempODWindow tempWindow = windowState->AcquireODWindow(ev, window);
- THROW_IF_NULL (tempWindow);
-
- rootFrame = tempWindow->GetRootFrame(ev);
-
- arbitrator->RelinquishFocus(ev,
- gCASession->GetODSession()->Tokenize(ev, kODModalFocus), rootFrame);
-
- CA_CATCH_ALL
- CA_ENDTRY
-
- }
-
-
-
- //-------------------------------------------------------------------------
-
- pascal void CAInstallFocusNotification( CAFocusAcquiredProc focusAquiredProc,
- CAFocusLostProc focusLostProc,
- CADocumentRef document )
- {
- Environment* ev = gCASession->GetEV();
- ODWindowState* windowState = gCASession->GetODSession()->GetWindowState(ev);
- CAProxyExtension* proxyExt = kODNULL;
-
- CA_TRY
-
- TempODPart tempPart = ((CADocument*)document)->AcquireRootPart();
- proxyExt = (CAProxyExtension*)tempPart->AcquireExtension( ev, kCAProxyPartExtension );
- THROW_IF_NULL (proxyExt); // kODErrUnsupportedExtension
-
- CAFocusAcquiredProcUPP focusAquiredUPPHandler;
- CAFocusLostProcUPP focusLostUPPHandler;
-
- focusAquiredUPPHandler = (CAFocusAcquiredProcUPP) NewRoutineDescriptor((ProcPtr)focusAquiredProc,
- uppCAFocusAcquiredProcInfo,
- GetCurrentISA());
-
- focusLostUPPHandler = (CAFocusLostProcUPP) NewRoutineDescriptor((ProcPtr)focusLostProc,
- uppCAFocusLostProcInfo,
- GetCurrentISA());
-
- proxyExt->InstallCAFocusHandlers( ev, focusAquiredUPPHandler, focusLostUPPHandler, document);
-
- CA_CATCH_ALL
- CA_ENDTRY
-
- ODRelease (ev, proxyExt);
-
-
- }
-
-